package cn.pomit.springbootwork.lock.zk;

import org.apache.curator.framework.CuratorFramework;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.zookeeper.config.CuratorFrameworkFactoryBean;
import org.springframework.integration.zookeeper.lock.ZookeeperLockRegistry;
import org.springframework.web.client.RestTemplate;

@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class LockZkApplication {
	@Value("${zookeeper.connectionString}")
	private String connectionString;

	public static void main(String[] args) {
		SpringApplication.run(LockZkApplication.class, args);
	}

	@Bean
	@LoadBalanced
	RestTemplate restTemplate() {
		return new RestTemplate();
	}

	@Bean
	CuratorFrameworkFactoryBean curatorFramework() {
		return new CuratorFrameworkFactoryBean(connectionString);
	}

	@Bean
	ZookeeperLockRegistry zookeeperLockRegistry(CuratorFramework client) {
		return new ZookeeperLockRegistry(client);
	}

}
